package com.example.floatingpopulation.controller;

import com.example.floatingpopulation.common.Result;
import com.example.floatingpopulation.controller.request.FloatingPopulationPageRequest;
import com.example.floatingpopulation.entity.FloatingPopulation;
import com.example.floatingpopulation.service.FloatingPopulationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/floatingPopulation")
public class FloatingPopulationController {
    @Autowired
    FloatingPopulationService floatingPopulationService;


    @PostMapping("/save")
    public Result<String> save(@RequestBody FloatingPopulation obj) {
        floatingPopulationService.save(obj);
        return Result.success();
    }

    @PutMapping("/update")
    public Result<String> update(@RequestBody FloatingPopulation obj) {
        floatingPopulationService.update(obj);
        return Result.success();
    }


    @DeleteMapping("/delete/{id}")
    public Result<String> delete(@PathVariable Integer id){
        floatingPopulationService.deleteById(id);
        return Result.success();
    }


    @GetMapping("/list")
    public Result<String> list(){
        List<FloatingPopulation> list = floatingPopulationService.list();
        return Result.success(list);
    }


    @GetMapping("/page")
    public Result<String> page(FloatingPopulationPageRequest pageRequest){
        return Result.success(floatingPopulationService.page(pageRequest));
    }

}
